package com.toe.admin.controller;

import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.vo.user.UserUserVO;
import com.toe.user.service.UserUsertblService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userAdmin")
@Api(tags = "后台用户模块")
@Slf4j
public class UserController {
    @DubboReference
    private UserUsertblService dubboUserUsertblService;

    @ApiOperation(value = "分页查询用户列表")
    @GetMapping("/page/{pageNum}/{pageSize}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "pageNum",example = "1"),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", example = "5")
    })
    public JsonResult<JsonPage<UserUserVO>> pageUsers(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        JsonPage<UserUserVO> jsonPage = dubboUserUsertblService.getUserListByPage(pageNum, pageSize);
        return JsonResult.ok(jsonPage);
    }

    @ApiOperation(value = "根据id删除用户")
    @PostMapping("/delete/{id}")
    @ApiImplicitParam(value = "用户id", name = "id", example = "1")
    public JsonResult<Void> removeUser(@PathVariable Long id) {
        dubboUserUsertblService.removeUserById(id);
        return JsonResult.ok();
    }


    @ApiOperation(value = "修改字段进行封号")
    @PostMapping("/forbid/{id}")
    @ApiImplicitParam(value = "用户id", name = "id", example = "1")
    public JsonResult<Void> forbidById(@PathVariable Long id) {
        dubboUserUsertblService.forbidUserById(id);
        return JsonResult.ok();
    }

    @ApiOperation(value = "修改字段进行解封")
    @PostMapping("/release/{id}")
    @ApiImplicitParam(value = "用户id", name = "id", example = "1")
    public JsonResult<Void> recoverById(@PathVariable Long id) {
        dubboUserUsertblService.recoverUserById(id);
        return JsonResult.ok();
    }
}
